﻿<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" Theme="MSN_Finance" %>

<script runat="server">
    
    Dim name As String = "  "
    Dim image1 As images = New images()
    

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
      
       
        
        
    End Sub
    
    Public Sub formfieldtovariable()
        image1.id_image = Integer.Parse(txt_id_image.Text)
        image1.name = txt_name.Text
        image1.filename_extension = txt_filename_extension.Text
    End Sub
        
    
   
    Public Sub show_images_on_page()
        txt_id_image.Text = image1.id_image.ToString()
        txt_name.Text = image1.name
        txt_filename_extension.Text = image1.filename_extension
    End Sub
    
    Public Sub cleanfields()
        txt_id_image.Text = "0"
        txt_name.Text = ""
        txt_filename_extension.Text = ""
    End Sub

   

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        cleanfields()
    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        
      
        formfieldtovariable()
        image1.insert()
        lbl_info.Text = "Success!"
        lbl_info.ForeColor = Drawing.Color.Purple
            
        
    End Sub
    
    Public Sub variabletoformfield()
        txt_id_image.Text = image1.id_image.ToString()
        txt_name.Text = image1.name
        txt_filename_extension.Text = image1.filename_extension
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        
        image1.name = txt_name.Text
        image1.filename_extension = txt_filename_extension.Text
        
        lbl_info.Text = "Success!" + image1.update()
        lbl_info.ForeColor = Drawing.Color.Purple
        
    End Sub


    Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        image1.first()
        variabletoformfield()
        
        
    End Sub

    Protected Sub Button7_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        formfieldtovariable()
        image1.next_image()
        variabletoformfield()
        
    End Sub

    Protected Sub Button6_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        formfieldtovariable()
        image1.previous_image()
        variabletoformfield()
    End Sub

      
 
  
Protected Sub Button9_Click(ByVal sender As Object, ByVal e As System.EventArgs)
      formfieldtovariable()
        image1.delete()
        variabletoformfield()
End Sub

    Protected Sub Button8_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
 
        image1.last_image()
        variabletoformfield()
  
    End Sub
    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs)
      
        '' If IsPostBack Then
        ''Response.Write("Postback")
        ''End If
        
        Dim connection_string As String = ConfigurationManager.ConnectionStrings("conn").ConnectionString
        Dim Sqlconnection1 As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection()
        Sqlconnection1.ConnectionString = connection_string
        Sqlconnection1.Open()
        Dim SqlCommand1 As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand()
        Dim string_sql As String = "Select * From images"
        SqlCommand1.Connection = Sqlconnection1
        SqlCommand1.CommandText = string_sql
        GridView1.DataKeyNames = New String() {"id_image"}
        GridView1.DataSource = SqlCommand1.ExecuteReader()
        GridView1.DataBind()
        
        SqlCommand1.Connection.Close()
        
        
    End Sub

   
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Page.ClientScript.RegisterStartupScript("".GetType(), "ClientScript", "alert('" + GridView1.SelectedValue.ToString() + "');", True)
        ' image1.id_image = Integer.Parse(GridView1.SelectedValue.ToString())

        image1.id_image = GridView1.SelectedValue.ToString()
        
        image1.select_image_by_id()
        variabletoformfield()
        
        'txt_name.Text = GridView1.SelectedRow.Cells(2).Text
        ' txt_filename_extension.Text = image1.filename_extension
        
    End Sub

 

    Protected Sub GridView1_RowDeleting1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)
        '  Page.ClientScript.RegisterStartupScript("".GetType(), "ClientScript", "alert('rowindex:" + e.RowIndex.ToString() + "';", True)
        ' Page.ClientScript.RegisterStartupScript("".GetType(), "ClientScript", "alert('id:" + GridView1.Rows(e.RowIndex).Cells(2).Text + "');", True)
        
        'image1.id_image = Integer.Parse(GridView1.Rows(e.RowIndex).Cells(2).Text)
        'image1.delete()
        ' cleanfields()
        jccc.utilidades.utilidades_java.mensagem(Page, jccc.utilidades.encriptacao.gerapassword(8))
        
        
    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style1
        {
            height: 26px;
        }
    </style>
</asp:Content>





<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <h1> Images </h1>
    <table width="100%">
    <tr>
        <td class="style1">
            <asp:Label ID="Lbl_id_image" runat="server" Text="id_image"></asp:Label>
        </td>
         <td class="style1">
             <asp:TextBox ID="txt_id_image" runat="server" ReadOnly="true" Text="0"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Lbl_name" runat="server" Text="name"></asp:Label>
        </td>
         <td>
             <asp:TextBox ID="txt_name" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Lbl_filename_extension" runat="server" Text="filename_extension"></asp:Label>
        </td>
         <td>
             <asp:TextBox ID="txt_filename_extension" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
       <td>
         </td>
        <td>
         
            <asp:Button ID="Button2" runat="server" Text="Clear" onclick="Button2_Click" />
            <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Insert" />
            <asp:Button ID="Button4" runat="server" Text="Update" onclick="Button4_Click" />
            <asp:Button ID="Button5" runat="server" Text="<<" onclick="Button5_Click" />
            <asp:Button ID="Button6" runat="server" Text="<" onclick="Button6_Click" />
            <asp:Button ID="Button7" runat="server" Text=">" onclick="Button7_Click" />
            <asp:Button ID="Button8" runat="server" Text=">>" onclick="Button8_Click1" />
            <asp:Button ID="Button9" runat="server" onclick="Button9_Click" Text="Delete" />
            <asp:Label ID="lbl_info" runat="server"></asp:Label>
        </td>
        
    </tr>
    <tr>
       <td colspan="2">
           <asp:GridView ID="GridView1" runat="server" 
               onselectedindexchanged="GridView1_SelectedIndexChanged" 
               onrowdeleting="GridView1_RowDeleting1" >
               <Columns>
                   <asp:CommandField HeaderText="Select" ShowHeader="True" ShowSelectButton="True" />
                   <asp:CommandField ButtonType="Button" HeaderText="Delete" 
                       ShowDeleteButton="True" ShowHeader="True" />
               </Columns>
           </asp:GridView>
         </td>
        
    </tr>
    </table>



</asp:Content>

